<!-- PAGE CONTENT WRAPPER -->
<div class="page-content-wrap">
    <div class="row">
        <div class="col-md-12">

            <form class="form-horizontal">
                <div class="panel panel-default">
                    <input name="go" value="${param.go}" type="hidden">
                    <div class="panel-heading">
                        <h3 class="panel-title" id="title"></h3>
                        <ul class="panel-controls">
                            <li><a href="javascript:window.location.href=document.referrer;"><i class="fa fa-arrow-left"></i></a></li>
                        </ul>
                    </div>
                    <div class="panel-body">
                        <p>在这里新增或者修改一个维修人员。</p>
                    </div>

                    <input type="hidden" id="repairPersonId" value="${repairPerson.id}">

                    <div class="panel-body">
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="col-md-3 control-label">姓名</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="name"
                                                   value="${repairPerson.name}"/>
                                        </div>
                                        <div id="nameValid"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">手机号</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="mobile"
                                                   value="${repairPerson.mobile}"/>
                                        </div>
                                        <div id="mobileValid"></div>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">维修分类</label>

                                    <div class="col-md-9">
                                        <select class="form-control select" id="categoryId">
                                            <c:forEach var="par" items="${categoryRepository.findByParentId(0)}">
                                                <option value="${par.id}"
                                                        <c:if test="${repairPerson.categoryId==par.id}">selected</c:if>>${par.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-md-3 control-label">职务</label>

                                    <div class="col-md-9">
                                        <div class="input-group">
                                            <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                                            <input type="text" class="form-control" id="post"
                                                   value="${repairPerson.post}"/>
                                        </div>
                                        <div id="postValid"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="panel-footer">
                            <span class="btn btn-primary pull-right" onclick="submita()">保存</span>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>

</div>
<!-- END PAGE CONTENT WRAPPER -->
<script>
    var repairPersonId;
    function submita() {
        var param = {};
        param.id = repairPersonId == '' ? -1 : repairPersonId;
        param.categoryId = $('#categoryId').val();
        param.name = $('#name').val();
        param.mobile = $('#mobile').val();
        param.post = $('#post').val();
        if (!param.name || param.name == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请输入姓名！</label>';
            $('#nameValid').html(vhtml);
            return false;
        }
        if (!param.mobile || param.mobile == '') {
            var vhtml = '<label id="re-password-error" class="error" for="re-password">请输入手机号！</label>';
            $('#mobileValid').html(vhtml);
            return false;
        }

        json("/admin/repair/saveRepairPerson.jspx", {param: JSON.stringify(param)}, function (data) {
            window.location.href = document.referrer;
        });
    }
    function submitb() {
        setTimeout(function () {
            submita();
        }, 100);
    }

    $(function () {
        repairPersonId = $('#repairPersonId').val();
        $('#title').html(repairPersonId == '' ? '添加维修人员' : '修改维修人员');
    });
</script>
